import sbtassembly.MergeStrategy

ThisBuild / version := "0.1"
ThisBuild / scalaVersion := "2.12.14"
ThisBuild / organization := "com.example"

val defaultMergeStrategy: String => MergeStrategy = {
  case x if Assembly.isConfigFile(x) =>
    MergeStrategy.concat
  case PathList(ps @ _*) if Assembly.isReadme(ps.last) || Assembly.isLicenseFile(ps.last) =>
    MergeStrategy.rename
  case PathList(ps @ _*) if ps.last.endsWith(".class") || ps.last.endsWith(".xml") || ps.last.endsWith(".properties")=>
    MergeStrategy.first
  case PathList(ps @ _*) if ps.last.endsWith(".dtd") || ps.last.endsWith(".xsd") || ps.last.endsWith(".html") || ps.last.endsWith(".css") =>
    MergeStrategy.first
  case PathList("META-INF", xs @ _*) =>
    (xs map {_.toLowerCase}) match {
      case ("manifest.mf" :: Nil) | ("index.list" :: Nil) | ("dependencies" :: Nil) =>
        MergeStrategy.discard
      case ps @ (x :: xs) if ps.last.endsWith(".sf") || ps.last.endsWith(".dsa") =>
        MergeStrategy.discard
      case "plexus" :: xs =>
        MergeStrategy.discard
      case "services" :: xs =>
        MergeStrategy.filterDistinctLines
      case ("spring.schemas" :: Nil) | ("spring.handlers" :: Nil) =>
        MergeStrategy.filterDistinctLines
      case _ => MergeStrategy.deduplicate
    }
  case _ => MergeStrategy.deduplicate
}

lazy val app = (project in file("."))
  .settings(
    name := "sbt-demo",
    libraryDependencies ++= Seq(
      "org.apache.spark" %% "spark-core" % "3.1.2",
      "org.apache.spark" %% "spark-sql" % "3.1.2",
      "org.apache.spark" %% "spark-hive" % "3.1.2",
      "org.scalatest" %% "scalatest" % "3.2.9" % Test
    ),
    assembly / assemblyMergeStrategy := defaultMergeStrategy,
    assembly / assemblyJarName := "sbt-demo.jar"
  )